import {Component} from '@angular/core';
import {IonicPage, ModalController} from 'ionic-angular';
import {ChatProvider} from "@providers/interface/chat";


@IonicPage()
@Component({
  selector: "page-message-home",
  templateUrl: 'message.home.html',
})
export class MessageHomePage {
  room_list: any[] = [];

  constructor(private modal: ModalController,
              private chat: ChatProvider) {
  }

  ionViewDidEnter() {
    this.getRoomList();
  }

  getRoomList(): Promise<any> {
    return new Promise((resolve) => {
      this.chat.getRoomList().then(v => {
        this.room_list = v['room_list'];
        resolve()
      }).catch(e => resolve())
    })
  }

  openRoom(item) {
    let _modal = this.modal.create("ChatPage", {...{}, ...item});
    _modal.present();
  }

  refresh(refresher?: any) {
    this.getRoomList().then(v => {
      if (refresher) {
        setTimeout(() => {
          refresher.complete();
        }, 500);
      }
    })
  }
}
